<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // for (var i = 0; i < 5; i++) {
      //   setTimeout(function () {
      //     console.log(i)
      //   }, 1000)
      // }

      for (var i = 0; i < 5; i++) {
        ;(function (i) {
          setTimeout(function () {
            console.log(i)
          }, 1000)
        })(i)
      }

// 闭包
      function fn(province){
        return function(city){
          return function(area){
            console.log(`${province}省${city}市${area}区`);
          }
        }
      }
      const fn1 = fn('浙江')('温州')
      fn1('瓯海')
      fn1('苍南')




      function person(name,age){
        this.name=name
        this.age = age
        return 100
      }
      person.prototype.say=function(){
        console.log('说话');
      }
      var zs = new person('张三',20)
      console.log(zs.age);//20
      console.log(zs.name);//张三




      const arr = [2,3,4]
      const arr1 = [4,5,6]
      Array.prototype.sum = function(){
        return this.reduce((sum,item)=>sum+item,0)
      }
      console.log(arr.sum());
      console.log(arr1.sum());


      var a = 100
      function fn3(){
        console.log(this.a);
      }
      var obj = {
        a:200
      }
      fn3.call(obj)
      fn3.apply(obj)
      var fn2 = fn.bind(obj)



      var a = 100
      function fn(m,n){
        console.log(this.a+m+n);
      }
      var obj = {
        a:200
      }
      fn.call(obj,2,3)
      fn.apply(obj,[2,3])



      const arr2 = [2,3,4,5]
    console.log(  Math.max.apply(null,arr));
    console.log(  Math.min.apply(null,arr));



    function person(name,age){
      this.name = name
      this.age = age
    }
    person.prototype.say = function(){
      console.log('说话');
    }
    function student(name,age,subject){
      this.name = name
      this.age = age
      this.subject = subject
    }
    subject.prototype = new person()
    student.prototype.constructor = student
    var zs = new student('张三',20,'前端')
    zs.say()



    function person(name,age){
      this.name = name
      this.age = age
    }
    person.prototype.say = function(){
      console.log('说话');
    }
    function student(name,age,subject){
      person.call(this,name,age)
      this.subject = subject
    }
    var zs = new student('张三',20,'前端')
    console.log(zs);



    class person{
      constructor(name,age){
        this.name = name
        this.age = age
      }
      say(){
        console.log('说话');
      }
    
    }
    class student extends person{
      constructor(name,age,subject){
        super(name,age)
        this.subject = subject
      }

    }
    var zs =  new student('张三',20,'前端')
    console.log(zs.name);
    zs.say()
    console.log(zs);
    </script>
  </body>
</html>
